//auto gen by paipai.java.augogen ver 1.0
//author skyzhuang
#ifndef _GISERPDAO_GIS_H_
#define _GISERPDAO_GIS_H_

#include <stdint.h>
#include <string>
#include <iostream>
#include "app_platform/help_macros.h"
#include "app_platform/intf_service.h"
#include "intf_giserpdao.h"

#include "library/basic/singleton_t.h"
#include "library/basic/sync_lock.h"
#include "c2cent/library/log/CWTimeElf3.h"

#include "erp/gis/ddo/shiptypearealocusdolist_gis.h"
#include "erp/gis/ddo/shiptypearealocusdo_gis.h"
#include "c2cent/storage/mysqlstorage.h"

HEADER_SELF_DEFINE_START
/**
*  请在这里增加自定义包含的头文件，否则无法合并代码
**/

HEADER_SELF_DEFINE_END

namespace erp
{
namespace gis
{
namespace dao
{

SERVICE class CGisErpDao : public IGisErpDao{
public:
		CGisErpDao(enum DeployMethod method = DEPLOY_STANDALONE);
		~CGisErpDao();
		 void Reset();
		static int Initialize(IUserDefineCntl* pCntl = NULL);

public:
	 /**
	 *
	 *   获取覆盖轨迹列表 
	 *
	 */
	EXPORT(0xc0241001) uint32_t GetMapCoverLocusList(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint32_t dwShipType,
		 uint32_t dwDestGbId,
		 const std::string& strInReserve,
		 erp::gis::ddo::CShipTypeAreaLocusDoList& oShipTypeAreaLocusDoList,
		 std::string& strErrMsg,
		 std::string& strOutReserve
		);

	 /**
	 *
	 *   同步配送区域轨迹记录 
	 *
	 */
	EXPORT(0xc0241002) uint32_t ShipTypeAreaLocusRowSync(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
		 const std::string& strInReserve,
		 std::string& strErrMsg,
		 std::string& strOutReserve
		);

SECTION_SELF_DEFINE_START
/**
*  请在这里增加自定义的成员变量和函数，否则无法合并代码
**/
private:
    uint32_t _GetMapCoverLocusListFromDB(
		 const CCntlInfo& rCntlInfo,
		 uint32_t dwShipType,
		 uint32_t dwDestGbCityId,
         C2C_TIME_ELF_ITIL& oWTimeElf,
		 erp::gis::ddo::CShipTypeAreaLocusDoList& oShipTypeAreaLocusDoList,
		 std::string& strErrMsg
         );

    uint32_t _GenerateGetMapCoverLocusListSql(
		 uint32_t dwShipType,
		 uint32_t dwDestGbCityId,
         std::stringstream& sql
         );

    uint32_t _GenerateUpdateShipTypeAreaLocusRowSql(
         const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
         std::stringstream& sql,
         c2cent::storage::CMySqlStorage& oStorage
         );

    void _AssignShipTypeAreaLocusDo(
         erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
         c2cent::storage::IResultSet& oRs 
         );

    static int _InitTmem(IUserDefineCntl* pCntl);

    std::string _GetTmemKey( 
		 uint32_t dwShipType,
		 uint32_t dwDestGbCityId
         );

    uint32_t _CheckCommParameter(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId
         );

    uint32_t _CheckCommParameter(
		 const CCntlInfo& rCntlInfo,
		 const std::string& strMachineKey,
		 const std::string& strSource,
		 uint32_t dwSceneId,
		 uint32_t dwShipType,
		 uint32_t dwDestGbCityId
         );

    uint32_t _ValidateShipTypeAreaLocusDo(
	    const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo
        );

    uint32_t _UpdateShipTypeAreaLocusRowInDB(
        const CCntlInfo& rCntlInfo,
        const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
        std::string& strErrMsg
        );

    uint32_t _GetShipTypeAreaLocusRowCountInDB(
        const CCntlInfo& rCntlInfo,
        const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
        uint32_t& dwRecordCount,
        std::string& strErrMsg
        );

    bool IsShipTypeAreaLocusRowExist(
        const CCntlInfo& rCntlInfo,
        const erp::gis::ddo::CShipTypeAreaLocusDo& oShipTypeAreaLocusDo,
        std::string& strErrMsg
        );


    uint32_t _GenerateGetShipTypeAreaLocusRecordCountSql(
         uint32_t dwShipType,
         uint32_t dwDestGbId,
         std::stringstream& sql
         );

private:
    uint16_t m_wUseSetId;
    static uint32_t m_dwTmemBid;
    static uint32_t m_dwMaxRecordNumPerArea; 
    static std::string m_strDBRole; 
    static std::string m_strShipAreaLocusTable; 
	static c2cent::library::wtimeelf::CItilGroup m_oShipTypeAreaLocusRowSync;
	static c2cent::library::wtimeelf::CItilGroup m_oGetMapCoverLocusList;

SECTION_SELF_DEFINE_END

private:
	enum DeployMethod m_method;
};

}
}
}

#endif /* _GISERPDAO_GIS_H_ */
